import iView from 'iview';
const common = {
  namespaced: true,
  state: {
    // 注册流
    registered: {
      page: 1, // 注册流程页码
    },
    submit: {
      Student_CityID: "",
      Student_ParentName: "",
      Student_Phone: "",
      Student_Sex: "",
      Student_Age: "",
    }
  },
  mutations: {
    registeredPage(state, payload) {
      state.registered.page = payload
    },
    updataRegistered(state, payload) {
      if (payload.state)
        state.registered.page++
      else
        state.registered.page--
    }
  },
  actions: {
    verification({
      commit
    }, param) {
      // 发送手机验证码
      global.POST(global.api.SendSMS, {
        Phone: global.$store.state.registered.submit.Student_Phone
      }).then(res => {
        if(param.state == undefined){
          commit('updataRegistered', {
            state: true
          })
        }else{
          param.suc()
        }
      })
    },
    VerificationCode({
      commit
    }, param) {
      // 验证手机验证码
      global.POST(global.api.CheckSMS, {
        Code: param
      }).then(res => {
        commit('updataRegistered', {
          state: true
        })
      })
    },
    touristsLanding({
      commit
    }, param) {
      // 游客登陆
      global.POST(global.api.SignIn, {
        CityID: param.id
      }).then(res => {
        global.router.replace({
          name: 'homeIndex'
        })
      })
    },
    GetSchoolListByCityID(context, param) {
      // 获取学校列表
      global.POST(global.api.GetSchoolListByCityID, {
        CityID: param.id
      }).then(res => {
        return param.suc(res)
      })
    },
    Register(context, param) {
      // 注册
      context.state.submit.Student_CityID = param.City.id;
      context.state.submit.Student_ParentName = param.ParentName1;
      context.state.submit.Student_ParentName1 = param.ParentName2;
      context.state.submit.Student_Sex = param.sex ? '男' : '女';
      context.state.submit.Student_Age = param.age;
      context.state.submit.Student_Name = param.name;
      context.state.submit.Student_SchoolID = param.schoolList;
      global.POST(global.api.Register, context.state.submit).then(res => {
        global.$store.state.com.user.info = res._Student
        return param.suc()
      })
    },
  },
  getters: {}
}
export default common